home *** CD-ROM | disk | FTP | other *** search
/ SIGGRAPH 2002 Course Notes / SIGGRAPH 2002 - Course Notes - Disc 1.iso / pc / notes / 16 / supplemental-material / Pharr / rim.sl < prev    next >
Encoding:
Text File  |  2002-04-05  |  573 b   |  29 lines

  1. /*
  2.  * rim.sl
  3.  *
  4.  * Rim lighting surface shader
  5.  *
  6.  * Matt Pharr <mmp@exluna.com>
  7.  *
  8.  */
  9.  
  10. float bias(varying float value, b) {
  11.     return (b > 0) ? pow(value, log(b) / log(0.5)) : 0;
  12. }
  13.  
  14. surface rim(float Ka=1, Kd=1, edgeWidth = .2) {
  15.     normal Nf = normalize(faceforward(N, I));
  16.     vector V = -normalize(I);
  17.  
  18.     illuminance(P, Nf, PI/2) {
  19.     vector Ln = normalize(L);
  20.     
  21.     float lightScale = Ln . Nf;
  22.     float edgeScale = bias(1 - (V . Nf), edgeWidth);
  23.     edgeScale = max(.7, 4*edgeScale);
  24.     Ci += Cl * Kd * lightScale * edgeScale;
  25.     }
  26.     Ci += Ka * ambient();
  27.     Ci *= Cs;
  28. }
  29.